package com.example.fashionshoes.config;

import com.example.fashionshoes.interceptor.JwtFreshInterceptor;
import com.example.fashionshoes.interceptor.JwtInterceptor;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Component
public class WebConfig implements WebMvcConfigurer {
    @Resource
    private JwtInterceptor jwtInterceptor;
    @Resource
    private JwtFreshInterceptor jwtFreshInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> addPath = new ArrayList<>();
        addPath.add("/cart/**");
        addPath.add("/order/**");
        addPath.add("/address/**");
        addPath.add("/user/changePassword");
        addPath.add("/user/modify");
        addPath.add("/user/info");
        addPath.add("/user/upload");
        addPath.add("/collect/**");
        addPath.add("/coupon/**");
        registry.addInterceptor(jwtInterceptor).addPathPatterns(addPath);
        //刷新token
        registry.addInterceptor(jwtFreshInterceptor).addPathPatterns("/**");
    }
}
